package baoxiu.service.impl;

import baoxiu.dto.BuildDetailTotal;
import baoxiu.dto.BuildTotal;
import baoxiu.dto.GoodsTotal;
import baoxiu.dto.RepaireDTO;
import baoxiu.mapper.RepaireMapper;
import baoxiu.entity.Repaire;
import baoxiu.service.RepaireService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @ClassName RepaireServiceImpl
 * @Author mengjiafeng
 * @Date 2019/7/25 9:53
 **/
@Service
public class RepaireServiceImpl extends
        ServiceImpl<RepaireMapper,Repaire> implements RepaireService {
    @Autowired
    RepaireMapper repaireMapper;
    @Override
    public List<RepaireDTO> getAllRepaireByUId(String userId) {
        return repaireMapper.getAllRepaireById(userId);
    }

    @Override
    public List<Repaire> getAllRepaireByRepaireStatus() {
        return repaireMapper.selectList(new QueryWrapper<Repaire>()
                .eq("repaire_status", 0));

    }

    @Override
    public void toRepaire(String repairemainId, String rid) {
        Repaire repaire = repaireMapper.selectById(rid);
        if (repaire.getRepaireStatus().equals("1")){
            throw new RuntimeException("该订单已被其他维修员接取");
        }
        repaire.setRepaireStatus("1");
        repaire.setConfirmStatus("0");
        repaire.setRepairemanId(repairemainId);
        repaire.setGetRepaireTime(new Date());
        repaireMapper.updateById(repaire);
    }

    @Override
    public List<GoodsTotal> getGoodsTotal() {
        return repaireMapper.getGoodsTotal();

    }

    @Override
    public List<BuildTotal> getBuildTotal() {
        return repaireMapper.getBuildTotal();
    }

    @Override
    public List<BuildDetailTotal> getBuildDetailTotal() {
         return repaireMapper.getBuildDetailTotal();
    }


}
